package com.canieatit.app;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class BarcoderActivity extends ParentActivity {
	private final static String TAG = "BarcoderActivity";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button.OnClickListener mScan = new Button.OnClickListener() {
            public void onClick(View v) {
//                Intent intent = new Intent("com.google.zxing.client.android.SCAN");
//                intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
//                startActivityForResult(intent, 0);
            	
            	Intent intent = new Intent(BarcoderActivity.this, BarcodeCheckerActivity.class);
            	intent.putExtra(EXTRA_BARCODE_NUMBER, TESTING_BARCODE);
            	intent.putExtra(EXTRA_BARCODE_FORMAT, TESTING_FORMAT);
            	startActivity(intent);
            	
             
            }
        };
        
        Button scanButton = (Button) findViewById(R.id.button1);
        
        scanButton.setOnClickListener(mScan);
       
    }
    
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                String contents = intent.getStringExtra("SCAN_RESULT");
                String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
                Log.i(TAG, "Result, barcode : "+contents+" , format: "+format);
                Intent i = new Intent(BarcoderActivity.this, BarcodeCheckerActivity.class);
                i.putExtra("barcodeNumber", contents);
                i.putExtra("barcodeFormat", format);
                startActivity(i);
                
            } else if (resultCode == RESULT_CANCELED) {
                // Handle cancel
            }
        }
    }
}